//
//  Topic_SearchViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 2016/12/5.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Topic_SearchViewController.h"

#import "Mine_TopicMineTableViewCell.h"

@interface Topic_SearchViewController () <UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITextField * text_Search;

@property (nonatomic, strong) UITableView * tableView;

@property (nonatomic, assign) NSInteger number;

@end

@implementation Topic_SearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];  
    
    self.number = 0;
    
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    _lblTitle.hidden = YES;
    
    _topView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    UIView * view_wihte = [[UIView alloc] initWithFrame:CGRectMake(15, 20 + 8, SCREEN_WIDTH - 70 - 15, 30)];
    view_wihte.backgroundColor = [UIColor whiteColor];
    view_wihte.layer.cornerRadius = 5;
    [_topView addSubview:view_wihte];
    
    UIImageView * image_saerch = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7.5, 15, 15)];
    image_saerch.image = [UIImage imageNamed:@"search_gray.png"];
    [view_wihte addSubview:image_saerch];
    
    self.text_Search = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_saerch.frame) + 5, 2.5, SCREEN_WIDTH - 85 - CGRectGetMaxX(image_saerch.frame) - 5 - 5, 25)];
    self.text_Search.delegate = self;
    self.text_Search.placeholder = @"输入关键字";
    self.text_Search.returnKeyType = UIReturnKeySearch;
    [view_wihte addSubview:self.text_Search];
    
    UIButton * btn_cancel = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_cancel.frame = CGRectMake(SCREEN_WIDTH - 60, 30, 50, 30);
    [btn_cancel setTitle:@"取消" forState:(UIControlStateNormal)];
    [btn_cancel setTitleColor:[UIColor colorWithRed:90/255.0 green:167/255.0 blue:239/255.0 alpha:1.0] forState:(UIControlStateNormal)];
    [_topView addSubview:btn_cancel];
    [btn_cancel addTarget:self action:@selector(btn_cancelAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_cancelAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (BOOL )textFieldShouldReturn:(UITextField *)textField
{
    if([textField.text length] != 0)
    {
        self.number = 3;
        
        dispatch_async(dispatch_get_main_queue(), ^{
            //刷新tableView(记住,要更新放在主线程中)
            [self.tableView reloadData];
        });
    }
    
    return YES;
}


//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [self.text_Search becomeFirstResponder];
    
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
    //
    [self.tableView registerClass:[Mine_TopicMineTableViewCell class] forCellReuseIdentifier:@"cell_topicSearch"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.number;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0f;
}

- (UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Mine_TopicMineTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_topicSearch" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.name.text = @"#战报#";
    cell.number.text = [NSString stringWithFormat:@"%ld24",indexPath.row + 1];
    
    cell.btn_select.layer.borderColor = [UIColor orangeColor].CGColor;
    cell.btn_select.tag = indexPath.row + 1000;
    [cell.btn_select setTitle:@"关注" forState:(UIControlStateNormal)];
    [cell.btn_select setTitleColor:[UIColor orangeColor] forState:(UIControlStateNormal)];
    [cell.btn_select addTarget:self action:@selector(btn_select1Action:) forControlEvents:(UIControlEventTouchUpInside)];
    
    return cell;
}

#pragma mark - 点击关注
- (void )btn_selectAction:(UIButton *)sender
{
    //    NSInteger count = sender.tag - 100;
    //    NSLog(@"%ld",count);
    
    NSLog(@"取消关注");
}

- (void )btn_select1Action:(UIButton *)sender
{
    //    NSInteger count = sender.tag - 1000;
    //    NSLog(@"%ld",count);
    
    NSLog(@"关注");
}













@end
